﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

using Microsoft.WindowsCE.Forms;

namespace CEProxy
{
    class Program
    {
        internal const int HWND_BROADCAST = 0xffff;
        internal const int WM_SETTINGCHANGE = 0x001a;
        internal const int SPI_SETDESKWALLPAPER = 0x0014; // 20;

        static void Main(string[] args)
        {
            Console.WriteLine(args);

            if (args.Length == 2)
            {
                try
                {
                    switch (args[0])
                    {
                        case "setdeskwallpaper":                            
                            SetDeskwallpaper(args);
                            break;

                        case "shellex":
                            ShellEx(args);
                            break;

                        default:
                            // nothing to do
                            break;
                    }
                }
                catch (Exception ex)
                {
                    // TODO: log to \temp on device
                }
            }
        }

        private static void ShellEx(string[] args)
        {
            string devicePath = args[1];
            if (File.Exists(devicePath))
            {
                var startInfo = new ProcessStartInfo
                                    {
                                        FileName = devicePath,
                                        UseShellExecute = true,
                                        Verb = "Open"
                                    };

                Process.Start(startInfo);
            }
        }

        private static void SetDeskwallpaper(string[] args)
        {
            string devicePath = args[1];
            if (File.Exists(devicePath))
            {
                NativeMethods.SetDeskWallpaper(devicePath);
            }
        }
    }
}
